# Maintainer: Alexey Pavlov <alexpux@gmail.com>

_realname=libdca
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=0.0.7
pkgrel=1
pkgdesc="Free library for decoding DTS Coherent Acoustics streams (mingw-w64)"
provides=("${MINGW_PACKAGE_PREFIX}-libdts")
replaces=("${MINGW_PACKAGE_PREFIX}-${_realname}-svn" "${MINGW_PACKAGE_PREFIX}-${_realname}-git" "${MINGW_PACKAGE_PREFIX}-libdts")
conflicts=("${MINGW_PACKAGE_PREFIX}-${_realname}-svn" "${MINGW_PACKAGE_PREFIX}-${_realname}-git" "${MINGW_PACKAGE_PREFIX}-libdts")
arch=('any')
url="https://www.videolan.org/developers/libdca.html"
license=("GPL")
makedepends=("${MINGW_PACKAGE_PREFIX}-gcc" "${MINGW_PACKAGE_PREFIX}-pkg-config")
options=('strip' 'staticlibs')
source=(https://download.videolan.org/pub/videolan/${_realname}/${pkgver}/${_realname}-${pkgver}.tar.bz2
        0001-Proper-use-of-destdir.all.patch
        0004-fix-regex.all.patch)
sha256sums=('3a0b13815f582c661d2388ffcabc2f1ea82f471783c400f765f2ec6c81065f6a'
            '9673c6ce186c6ba4188720cf746670484094420f56468cec5d0ce392483c0cac'
            '64eb68329b4dd4276907c61b560e8c8f19120b868560e04ab3b686f1c6fab81e')

prepare() {
  cd "${srcdir}/${_realname}-${pkgver}"
  patch -p1 -i ${srcdir}/0001-Proper-use-of-destdir.all.patch
  patch -p1 -i ${srcdir}/0004-fix-regex.all.patch

  autoreconf -fi
}

build() {
  [[ -d ${srcdir}/build-${MINGW_CHOST} ]] && rm -rf ${srcdir}/build-${MINGW_CHOST}
  mkdir -p ${srcdir}/build-${MINGW_CHOST} && cd ${srcdir}/build-${MINGW_CHOST}

  ../${_realname}-${pkgver}/configure \
    --prefix=${MINGW_PREFIX} \
    --build=${MINGW_CHOST} \
    --host=${MINGW_CHOST} \
    --enable-static \
    --enable-shared \
    --mandir=${MINGW_PREFIX}/share/man

  make
}

package() {
  cd build-${MINGW_CHOST}
  make DESTDIR="${pkgdir}" install

  rm -f "${pkgdir}${MINGW_PREFIX}/share/man/man1"/{extract_dts,dtsdec}.1
  cp "${pkgdir}${MINGW_PREFIX}/share/man/man1/dcadec.1" "${pkgdir}${MINGW_PREFIX}/share/man/man1/dtsdec.1"
  cp "${pkgdir}${MINGW_PREFIX}/share/man/man1/extract_dca.1" "${pkgdir}${MINGW_PREFIX}/share/man/man1/extract_dts.1"

  install -Dm644 ${srcdir}/${_realname}-${pkgver}/COPYING ${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/COPYING
}
